/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package broadcast_recive;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 *
 * @author Xuan Cau
 */
public class Broadcast_recive {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        // khoi tao socket
        try
        {
            int port = 9875;
            DatagramSocket socket = new DatagramSocket(port);
            while(true)
            {
                //Nhan thong diep tu Client
                byte []rcvbuf = new byte[1024];
                //Tao DatagramPacket de nhan data
                DatagramPacket rcvpkt = new DatagramPacket(rcvbuf,rcvbuf.length);
                //Goi ham nhan DatagramPacket
                socket.receive(rcvpkt);
                String stRcv = new String(rcvpkt.getData(),0,rcvpkt.getLength());
                System.out.println("Client: "+ stRcv);
            }
        }
        catch(Exception ex)
        {
            
        }
    }
}
